package com.med.meddataintegrator.admin.service.Impl;

import com.med.meddataintegrator.common.mapper.HospitalizationDoMapper;
import com.med.meddataintegrator.common.mapper.PatientDoMapper;
import com.med.meddataintegrator.common.pojo.dos.HospitalizationDo;
import com.med.meddataintegrator.common.pojo.dto.hospitalization.HospitalizationAddParam;
import com.med.meddataintegrator.common.pojo.dto.hospitalization.HospitalizationQuery;
import com.med.meddataintegrator.common.pojo.dto.hospitalization.HospitalizationUpdateParam;
import com.med.meddataintegrator.common.pojo.vo.hospitalization.HospitalizationVo;
import com.med.meddataintegrator.admin.service.HospitalizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class HospitalizationServiceImpl implements HospitalizationService {
    @Autowired
    HospitalizationDoMapper hospitalizationMapper;
    @Autowired
    PatientDoMapper patientMapper;
    @Override
    public List<HospitalizationVo> select(HospitalizationQuery hospitalizationQuery) {
        log.debug("查询条件", hospitalizationQuery);
        List<HospitalizationVo> list = hospitalizationMapper.select(hospitalizationQuery);
        return list;
    }

    @Override
    public void add(HospitalizationAddParam hospitalizationAddParam) {
        log.debug("入院信息", hospitalizationAddParam);
        HospitalizationDo hospitalizationDo = new HospitalizationDo();
        BeanUtils.copyProperties(hospitalizationAddParam, hospitalizationDo);
        int id = patientMapper.selectByName(hospitalizationDo.getName());
        hospitalizationDo.setPatientId(id);
        hospitalizationMapper.insert(hospitalizationDo);
    }

    @Override
    public void update(HospitalizationUpdateParam hospitalizationUpdateParam) {
        log.debug("修改入院信息", hospitalizationUpdateParam);
        hospitalizationMapper.update(hospitalizationUpdateParam);
    }

    @Override
    public void delete(Integer id) {
        log.debug("删除入院信息", id);
        hospitalizationMapper.deleteById(id);
    }
}
